package com.zzzzzz.core.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

public class FileUploadValidator implements Validator{
	 
//	@Override
	public boolean supports(Class clazz) {
		//just validate the FileUpload instances
		return CommonsMultipartFile.class.isAssignableFrom(clazz);
	}
 
//	@Override
	public void validate(Object target, Errors errors) {
 
		CommonsMultipartFile file = (CommonsMultipartFile)target;
		
		if(!"image/jpeg".equals(file.getContentType())&&!"image/gif".equals(file.getContentType())&&!"image/png".equals(file.getContentType())){
			errors.rejectValue("fileData", "required.contentType");
		}
	}
}
